import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)



/* Layout */
import Layout from '@/views/layout/Layout'


const login = r => require.ensure([], () => r(require('@/views/login/index')), 'login');
const home = r => require.ensure([], () => r(require('@/views/home/index')), 'home');
const register = r => require.ensure([], () => r(require('@/views/home/register/index')), 'register');
const taskManage = r => require.ensure([], () => r(require('@/views/taskManage/index')), 'taskManage');
const taskHistory = r => require.ensure([], () => r(require('@/views/taskManage/taskHistory/index')), 'taskHistory');
const taskEntry = r => require.ensure([], () => r(require('@/views/taskManage/taskEntry/newIndex')), 'taskEntry');
const taskProgress = r => require.ensure([], () => r(require('@/views/taskManage/taskProgress/index')), 'taskProgress');
const taskMine = r => require.ensure([], () => r(require('@/views/taskManage/taskMine/index')), 'taskMine');
const worksExcellence = r => require.ensure([], () => r(require('../views/taskManage/worksExcellence/index.vue')), 'worksExcellence');
const userManage = r => require.ensure([], () => r(require('@/views/userManage/index')), 'userManage');
const userList = r => require.ensure([], () => r(require('@/views/userManage/userList/index')), 'userList');
const leaderManage = r => require.ensure([], () => r(require('@/views/userManage/userList/leaderManage/index')), 'leaderManage');
const materialManage = r => require.ensure([], () => r(require('@/views/userManage/materialManage/index')), 'materialManage');
const costManage = r => require.ensure([], () => r(require('@/views/userManage/costManage/index')), 'costManage');
const brandManage = r => require.ensure([], () => r(require('@/views/userManage/brandManage/index')), 'brandManage');
const reportManage = r => require.ensure([], () => r(require('@/views/reportManage/index')), 'reportManage');
const reportBrand = r => require.ensure([], () => r(require('@/views/reportManage/reportBrand/newIndex')), 'reportBrand');
const reportUser = r => require.ensure([], () => r(require('@/views/reportManage/reportUser/index')), 'reportUser');
const reportDivisional = r => require.ensure([], () => r(require('@/views/reportManage/reportDivisional/index')), 'reportDivisional');
const reportIntraclass = r => require.ensure([], () => r(require('@/views/reportManage/reportIntraclass/index')), 'reportIntraclass');
const permAssignment = r => require.ensure([], () => r(require('../views/PermAssignment/authority/index')), 'permAssignment');


export const constantRouterMap = [
    {
        path: '/login',
        component: login,
        hidden: true,
    }, 
    {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
        hidden: true,
        children: [{
            path: '/dashboard',
            component: home,
            meta: {
                title: '首页',
                noCache: true //如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
            },
        }]
    }, 
    {
        path: '/register',
        component: Layout,
        redirect: '/register',
        hidden: true,
        children: [{
            path: '/register',
            component: register,
            name: 'register',
            meta: {
                title: '修改密码',
            }
        }]
    },
    {
        path: '/404',
        component: () => import('@/views/404'),
        hidden: true
    },
]

/* 初始路由 */
export default new Router({
    // mode: 'history', //后端支持可开
    scrollBehavior: () => ({
        y: 0
    }),
    routes: constantRouterMap
})

export const asyncRouterMap = [{
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
        path: '/dashboard',
        component: home,
        meta: {
            title: '首页',
        }
    }]
}]


/* 需要权限判断的路由 */
export const allRoutes = [
    {
        path: '/taskManage',
        component: Layout,
        name: 'taskManage',
        redirect: '/taskManage/taskEntry',
        alwaysShow: true, //显示根路由
        meta: {
            title: '任务',
            icon: 'icon-task',
        },
        children: [
            {
                path: 'taskEntry',
                component: taskManage,
                name: 'taskEntry',
                redirect: '/taskManage/taskEntry/taskentry',
                meta: {
                    title: '任务录入',
                },
                children: [{
                    path: 'taskentry',
                    component: taskEntry,
                    name: "taskentry",
                    meta: {
                        title: '任务录入'
                    }
                }]
            },
            {
                path: 'taskProgress',
                component: taskProgress,
                name: 'taskProgress',
                meta: {
                    title: '任务进度',
                }
            },
            {
                path: 'taskMine',
                component: taskMine,
                name: 'taskMine',
                meta: {
                    title: '我的审批',
                }
            },
            {
                path: 'taskHistory',
                component: taskHistory,
                name: 'taskHistory',
                meta: {
                    title: "任务历史"
                }
            },
            {
                path: '/worksExcellence',
                component: worksExcellence,
                name: 'worksExcellence',
                meta: {
                    title: "优秀作品"
                }
            }
        ]
    }, 
    {
        path: '/userManage',
        component: Layout,
        redirect: '/userManage/userList',
        name: 'userManage',
        alwaysShow: true, //显示根路由
        meta: {
            title: '管理',
            icon: 'icon-manage',
        },
        children: [
            {
                path: 'userList',
                component: userManage,
                redirect: '/userManage/userList/leaderManage',
                name: 'userList',
                meta: {
                    title: '员工管理',
                },
                children: [{
                    path: 'userlist',
                    component: userList,
                    name: 'userlist',
                    meta: {
                        title: '员工管理',
                    }
                }, {
                    path: 'leaderManage',
                    component: leaderManage,
                    name: 'leaderManage',
                    hidden: true,
                    meta: {
                        title: '组长管理',
                    }
                }]
            }, {
                path: 'brandManage',
                component: brandManage,
                name: "brandManage",
                meta: {
                    title: '品牌管理',
                }
            }, {
                path: 'materialManage',
                component: materialManage,
                name: "materialManage",
                meta: {
                    title: '物料管理',
                }
            }, {
                path: 'costManage',
                component: costManage,
                name: "costManage",
                meta: {
                    title: '成本中心管理',
                }
            }
        ]
    }, 
    {
        path: '/reportManage',
        component: Layout,
        name: 'reportManage',
        alwaysShow: true, //显示根路由
        meta: {
            title: '报表',
            icon: 'icon-form',
        },
        children: [{
            path: 'reportBrand',
            component: reportManage,
            name: 'reportBrand',
            meta: {
                title: '品牌报表',
            },
            children: [{
                path: 'reportbrand',
                component: reportBrand,
                meta: {
                    title: '品牌报表'
                }
            }]
        }, {
            path: 'reportUser',
            component: reportManage,
            name: 'reportUser',
            redirect: '/reportManage/reportUser/reportuser',
            meta: {
                title: '员工报表',
            },
            children: [{
                path: 'reportuser',
                component: reportUser,
                meta: {
                    title: '员工报表'
                }
            }]
        }, {
            path: '/reportIntraclass',
            component: reportIntraclass,
            name: 'reportIntraclass',
            meta: {
                title: '组内报表',
            }
        },
        {
            path: '/reportDivisional',
            component: reportDivisional,
            name: 'reportDivisional',
            meta: {
                title: '部门报表',
            }
        }
        ]
    },
    {
        path: '/permAssignment',
        component: Layout,
        name: 'bPermAssignment',
        alwaysShow: true, //显示根路由
        meta: {
            title: '权限',
            icon: 'icon-form',
        },
        children: [
            {
                path: '/permAssignment',
                component: permAssignment,
                name: 'permAssignment',
                meta: {
                    title: '权限设置',
                }
            }
        ]
    },
     //必须放最后
    {
        path: '*',
        redirect: '/404',
        hidden: true,
        meta: {
            title: '404',
        }
    }
]